package com.graduation.lastproject.util.defaultView;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * Created by lsf on 2018/6/5.
 * jiejian on2020 2.7
 */
@Component
public class DefauiltView implements CommandLineRunner {
    private static Logger logger = LoggerFactory.getLogger(DefauiltView.class);
    boolean falg=true;
    @Value("${spring.web.loginurl}")
    private String loginUrl;

    @Value("${spring.web.googleexcute}")
    private String googleExcutePath;

    @Value("${spring.auto.openurl}")
    private boolean isOpen;

    @Override
    public void run(String... args) throws Exception {
        if(falg) {
            if (isOpen) {
                String cmd = googleExcutePath + " " + loginUrl;
                Runtime run = Runtime.getRuntime();
                try {
                    run.exec(cmd);
                    logger.debug("启动浏览器打开项目成功");
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.error(e.getMessage());
                }
            }
        }
        //浏览器机制导致重复更新
        falg=false;
    }
}
